<script setup>
import OImage from "../setting/Images.vue";
import AlphaColor from "../setting/AlphaColor.vue";
import Slider from "../setting/Slider.vue";
import Color from "../setting/Color.vue";

const props = defineProps({
  config: {
    type: Object,
    required: true,
  },
  name: {
    type: String,
    default: "",
  },
  disabled: {
    type: Boolean,
    default: false,
  },
});

const emits = defineEmits(["update:config", "change"]);

const form = ref({
  $position: { top: 145, left: 41 },
  $positionType: "absolute",
  $size: { width: 306, height: 375 },
  $removeable: false,
  $mode: "popup",
  type: "sucess",
  borderRadius: 10,
  color: "#333333",
  scoreColor: "#EB4A73",
  bgColor: "#ffffff",
  scoreSize: 25,
  showBgImg: false,
  textPosition: { left: 15, top: 15 },
  textSize: { width: 270, height: 40 },
  prizePosition: { top: 100, left: 50 },
  prizeSize: { width: 200, height: 130 },
  goPrize: "./imagesStatic/activity/goprize.png",
  goPrizePosition: { top: 270, left: 90 },
  goPrizeSize: { width: 126, height: 57 },
  closeImg: "./imagesStatic/activity/close_icon.png",
  closePosition: {
    top: 385,
    left: 134,
  },
  closeImgSize: {
    width: 30,
    height: 30,
  },
});

const detail = computed({
  get: () => {
    return Object.assign({}, form.value, props.config);
  },
  set: (val) => {
    emits("update:config", val);
    emits("change", val);
  },
});

const onChange = (val) => {
  detail.value = detail.value;
};

onMounted(() => {
  nextTick(() => {
    onChange();
  });
});
</script>
<template>
  <el-form :model="detail" :disabled="disabled" label-width="auto">
    <Color v-model="detail.color" name="文字颜色" @change="onChange" />
    <Color v-model="detail.scoreColor" name="成绩颜色" @change="onChange" />
    <Slider
      v-model="detail.scoreSize"
      name="成绩字号"
      :min="12"
      :max="35"
      @change="onChange"
    />
    <AlphaColor v-model="detail.bgColor" name="背景色" @change="onChange" />
    <Slider
      v-model="detail.borderRadius"
      name="圆角"
      :max="20"
      @change="onChange"
    />
    <OImage
      v-model="detail.backgroundImg"
      v-model:size="detail.$size"
      v-model:show="detail.showBgImg"
      name="背景图片"
      @change="onChange"
    />
    <OImage
      v-model="detail.closeImg"
      v-model:size="detail.closeImgSize"
      name="关闭按钮"
      @change="onChange"
    />
    <OImage
      v-if="detail.type === 'success'"
      v-model="detail.goPrize"
      v-model:size="detail.goPrizeSize"
      name="领奖按钮"
      @change="onChange"
    />
  </el-form>
</template>
